
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region PresentRecord Model -(by fangyifeng at 2007-09-14 12:24:16)

	/// <summary>
	/// PresentRecord object'PresentRecord'.
	/// </summary>
	[Serializable]
	public class PresentRecord : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected DateTime _sendDate;
		protected string _giftInfo;
		protected Customer _customer;
		protected FriendInfo _friend;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public PresentRecord() { }

		public PresentRecord( DateTime sendDate, string giftInfo, Customer customer, FriendInfo friend )
		{
			this._sendDate = sendDate;
			this._giftInfo = giftInfo;
			this._customer = customer;
			this._friend = friend;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual DateTime SendDate
		{
			get { return _sendDate; }
			set { _sendDate = value; }
		}

		public virtual string GiftInfo
		{
			get { return _giftInfo; }
			set
			{
				if ( value != null && value.Length > 1000)
					throw new ArgumentOutOfRangeException("Invalid value for GiftInfo", value, value.ToString());
				_giftInfo = value;
			}
		}

		public virtual Customer Customer
		{
			get { return _customer; }
			set { _customer = value; }
		}

		
		public virtual FriendInfo Friend
		{
			get { return _friend; }
			set { _friend = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is PresentRecord))
				throw new InvalidCastException("This object is not of type PresentRecord");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((PresentRecord)obj).Id);
					break;
				case "SendDate":
					relativeValue = this.SendDate.CompareTo(((PresentRecord)obj).SendDate);
					break;
				case "GiftInfo":
					relativeValue = this.GiftInfo.CompareTo(((PresentRecord)obj).GiftInfo);
					break;
                default:
                    goto case "Id";
			}
            if (PresentRecord.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
